﻿using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Warning : CWSPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["Action"]))
            {
                ShowList();
                PayedBind();
                RenewBind();
            }
        }
    }

    private void ShowList()
    {
        if (Request.QueryString["Action"].ToString().Equals("Pay", StringComparison.CurrentCultureIgnoreCase))
        {
            PayedList.Visible = true;
            RenewList.Visible = false;
            Pay.Attributes.Add("class", "ui-btn-active ui-state-persist");
            Renew.Attributes.Remove("class");
        }
        else
        {
            RenewList.Visible = true;
            PayedList.Visible = false;
            Renew.Attributes.Add("class", "ui-btn-active ui-state-persist");
            Pay.Attributes.Remove("class");
        }
    }

    private void PayedBind()
    {
        string sqlstr = @"SELECT CID,T2.DataName AS Region,StationName,ContractNo,STRFTIME('%Y-%m-%d',PayDate) AS PayDate,ContractValue
                          FROM CW_CONTRACT_T T1
                          LEFT JOIN CW_PUBDATA_T T2
                            ON T1.[Region] = T2.[DataCode]
                           AND T2.DataType = 'Region' 
                         WHERE STATUS <> '删除'
                           AND PayDate < date('now','start of month','localtime','+4 months')
                         ORDER BY PayDate";
        PayedList.DataSource = SQLiteHelper.ExecuteDataset(sqlstr, null);
        PayedList.DataBind();
    }

    private void RenewBind()
    {
        string sqlstr = @"SELECT CID,T2.DataName AS Region,StationName,ContractNo,STRFTIME('%Y-%m-%d',EndDate) AS EndDate,ContractValue
                          FROM CW_CONTRACT_T T1
                          LEFT JOIN CW_PUBDATA_T T2
                            ON T1.[Region] = T2.[DataCode]
                           AND T2.DataType = 'Region' 
                         WHERE STATUS = '正常'
                           AND EndDate < date('now','start of month','localtime','+6 months')
                         ORDER BY EndDate";
        RenewList.DataSource = SQLiteHelper.ExecuteDataset(sqlstr, null);
        RenewList.DataBind();
    }
}
